package com.augurit.gzcgwsp.ywcmn.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dozer.DozerBeanMapper;

import com.augurit.gzcgwsp.ywcmn.entity.YwDzgzList;
import com.augurit.gzcgwsp.ywcmn.web.form.YwDzgzListForm;

public class YwDzgzListConvertor {
	public static YwDzgzListForm convertVoToForm(YwDzgzList entity) {
		if(entity != null) {
			YwDzgzListForm form = new DozerBeanMapper().map(entity, YwDzgzListForm.class);
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(YwDzgzListForm form, YwDzgzList entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			entity.setAjid(form.getAjid());
			entity.setUsername(form.getUsername());
			entity.setUploaddate(form.getUploaddate());
			entity.setTemplateCode(form.getTemplateCode());
			if(form.getFilename() != null && form.getFilename().trim().length() > 0)
				entity.setFilename(form.getFilename().trim());
			if(form.getFilepath() != null && form.getFilepath().trim().length() > 0)
				entity.setFilepath(form.getFilepath().trim());
		}
	}
	
	public static List<YwDzgzListForm> convertVoListToFormList(List<YwDzgzList> ywDzgzListList) {
		if(ywDzgzListList != null && ywDzgzListList.size() > 0) {
			List<YwDzgzListForm> ywDzgzListFormList = new ArrayList();
			for(int i=0; i<ywDzgzListList.size(); i++) {
				ywDzgzListFormList.add(convertVoToForm(ywDzgzListList.get(i)));
			}
			return ywDzgzListFormList;
		}
		return null;
	}
	
	public static List<Map> convertVoListToMapList(List<YwDzgzList> ywDzgzListList) {
		if(ywDzgzListList != null && ywDzgzListList.size() > 0) {
			List<Map> mapList = new ArrayList();
			for(int i=0; i<ywDzgzListList.size(); i++) {
				YwDzgzList entity = ywDzgzListList.get(i);
				Map<String, String> map = new HashMap();
				map.put("id", entity.getId() == null ? "" : entity.getId().toString());
				map.put("ajid", entity.getAjid() == null ? "" : entity.getAjid().toString());
				map.put("filename", entity.getFilename());
				map.put("filepath", entity.getFilepath());
				map.put("username", entity.getUsername());
				map.put("uploaddate", entity.getUploaddate()+"");
				map.put("templateCode",entity.getTemplateCode());
				mapList.add(map);
			}
			return mapList;
		}
		return null;
	}
	
	public static List<YwDzgzList> convertFormListToVoList(List<YwDzgzListForm> ywDzgzListFormList) {
		if(ywDzgzListFormList != null && ywDzgzListFormList.size() > 0) {
			List<YwDzgzList> ywDzgzListList = new ArrayList();
			for(int i=0; i<ywDzgzListFormList.size(); i++) {
				YwDzgzList ywDzgzList = new YwDzgzList();
				convertFormToVo(ywDzgzListFormList.get(i), ywDzgzList);
				ywDzgzListList.add(ywDzgzList);
			}
			return ywDzgzListList;
		}
		return null;
	}
}